package com.tsd.core.openweixin.model;

import java.util.Date;
import java.util.Objects;

/**
 * 微信JS接口的临时票据
 * ，jsapi_ticket是公众号用于调用微信JS接口的临时票据。正常情况下，jsapi_ticket的有效期为7200秒，通过access_token来获取。由于获取jsapi_ticket的api调用次数非常有限，频繁刷新jsapi_ticket会导致api调用受限，影响自身业务，开发者必须在自己的服务全局缓存jsapi_ticket 。
 * <p>
 * 参考以下文档获取access_token（有效期7200秒，开发者必须在自己的服务全局缓存access_token）：../15/54ce45d8d30b6bf6758f68d2e95bc627.html
 * 用第一步拿到的access_token 采用http GET方式请求获得jsapi_ticket（有效期7200秒，开发者必须在自己的服务全局缓存jsapi_ticket）：https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi
 * <p>
 * 成功返回如下JSON：
 * <p>
 * {
 * "errcode":0,
 * "errmsg":"ok",
 * "ticket":"bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA",
 * "expires_in":7200
 * }
 * <p>
 * 获得jsapi_ticket之后，就可以生成JS-SDK权限验证的签名了。
 *
 * @author hillpool
 */
public class JsapiTicket {

    private String ticket;
    private int errcode;
    private String errmsg;
    private long expires_in;
    private long expiresTimestemp;

//    public JsapiTicket(String ticket, Long expiresTimestemp) {
//        this.ticket = ticket;
//        this.expiresTimestemp = expiresTimestemp;
//    }


    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final JsapiTicket other = (JsapiTicket) obj;
        return Objects.equals(this.ticket, other.ticket);
    }

    @Override
    public String toString() {
        return "JsapiTicket{" + "ticket=" + ticket + ", expiresTimestemp=" + expiresTimestemp + "'(" + (new Date(expiresTimestemp)) + ")}";
    }


    public int getErrcode() {
        return errcode;
    }


    public void setErrcode(int errcode) {
        this.errcode = errcode;
    }


    public String getErrmsg() {
        return errmsg;
    }


    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }


    public long getExpires_in() {
        return expires_in;
    }


    public void setExpires_in(long expires_in) {
        this.expires_in = expires_in;
    }

    public String getTicket() {
        return ticket;
    }

    public void setTicket(String ticket) {
        this.ticket = ticket;
    }

    public long getExpiresTimestemp() {
        return expiresTimestemp;
    }

    public void setExpiresTimestemp(long expiresTimestemp) {
        this.expiresTimestemp = expiresTimestemp;
    }

}
